#ifndef __HTTPPARSE_H__
#define __HTTPPARSE_H__



#include "common.h"
#include "utils.h"
#include "gzip.h"

/*
 *@状态码;
 */
enum httpStatusCode{
	HTTP_PARTIAL_CODE = 206,
	HTTP_MOVED_CODE = 301,
	HTTP_FOUND_CODE = 302,
	HTTP_BAD_REQUEST_CODE = 400,
	HTTP_UNAUTHORIZED_COEE = 401,
	HTTP_FORBIDDEN_CODE = 403,
	HTTP_NOT_FOUND_CODE = 404,
	HTTP_REQUEST_RANGE_NOT_STATISFIABLE = 416,
	HTTP_INTERNAL_SERVER_ERROR = 500,
	HTTP_BAD_GATEWAY = 502,
	HTTP_SERVICE_UNAVALIABLE = 503,
	HTTP_REQUEST_COMPLETED = 200
};






/*
 *@brief:
 *
 *
 *
 */
int httpServerInit(struct httpServerCtx **http, struct serverConfigOpt *opt);


/*
 *@brief:
 *
 *
 *
 *
 */
int httpServerDeinit(struct httpServerCtx *httpctx);

/*
 *@brief:
 *
 *
 *
 *
 */
char * httpParseRequestHeader(char *start, char *end, int requestLen, struct httpMessage *msg);

/*
 *@brief:
 *
 *
 *
 *
 */
int httpGetRequestLen(struct connection *conn);

/*
 *@brief:
 *
 *
 *
 *
 */
int httpParseRequest(struct connection *conn, struct httpMessage *msg, bool isRequest);

/*
 *@brief:
 *
 *
 *
 */
void httpGmtTimeString(char *timebuf, int buflen, time_t *time);

/*
 *@brief: 
 *
 *
 *
 */
void httpConstructEtag(char *etagbuf, int etaglen, struct stat *indexfile);
/*
 *@brief:
 *
 *
 *
 */
double httpGetLocalTime();

/*
 *@brief:
 *
 *
 *
 */
int httpSendHttpFile(struct connection *conn, char *path, struct dynString *pathInfo, struct httpMessage *msg, struct httpServerCtx *httpctx);

/*
 *@brief:
 *
 *
 *
 */
int httpServeFile(struct connection *conn, char *path, struct httpMessage *msg, struct dynString extraHeaders);

/*
 *@brief:
 *
 *
 *
 *
 */
int httpSendResponseLine(struct connection *conn, int statusCode, char * extraHeaders);

/*
 *@brief:
 *@para:
 *
 *
 *
 */
char * httpStatusMessage(int errorCode);


/*
 *@brief:
 *@para:
 *
 *
 *
 */
int httpTransferFileData(struct connection *conn);


/*@brief:
 *@para:
 *
 *@return value:
 */
int handleHttpRequest(struct connection *conn, struct httpMessage *msg, struct httpServerCtx *httpctx);



/*@brief:
 *@para:
 *
 *@return value:
 */
int httpFreeProtoDataFile(struct httpOpt *opt);




/*@brief:
 *@para:
 *
 */
int bufferedFileData(struct connection *conn, char *buf,  size_t buffLen);



struct dynString *httpGetHttpHeader(struct httpMessage *hm, const char *name);







#endif 
